package modelPackage;

import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;

public class Bear extends Character {

	//Velocity in the X and Z planes should be the same, and a constant.
	static protected double vx = 0.275;
	static protected double vz = 0.275;
	
	
	/*
	 * This is the consturctor.
	 * */
	public Bear(Point position) {
		super(50, 50, position);				
		super.setPosXVelocity(true);	
		
		this.initializeAnimations();
	}
    
	
	 /*
     * This needs to be here because velocities are different for players and bears.
     */
    public void updateXPosition(long elapsedTime){
		super.updateXPosition(elapsedTime, vx);
	}
	public void updateZPosition(long elapsedTime) {
		super.updateZPosition(elapsedTime, vz);
	}
	

	@Override
	public void setPosXVelocity(boolean moveRight){
		
		if(moveRight){
			this.negX = false;
			this.posX = true;
		}
		else{
			setNegXVelocity(true);
		}
		
	}
	
	@Override
	public void setNegXVelocity(boolean moveLeft){
		if(moveLeft){
			this.negX = true;
			this.posX = false;
		}
		else{
			setPosXVelocity(true);
		}
	}




	/*
	 * This section deal with animations.
	 * */


	@Override
	public void initializeAnimations() {
		
		Animation only = new Animation("only");
		
		Image only0 = loadImage("images/Bear/player0.png");
		Image only1 = loadImage("images/Bear/player1.png");
		Image only2 = loadImage("images/Bear/player2.png");
		Image only3 = loadImage("images/Bear/player3.png");
		Image only4 = loadImage("images/Bear/player4.png");
		Image only5 = loadImage("images/Bear/player5.png");
		Image only6 = loadImage("images/Bear/player6.png");
		Image only7 = loadImage("images/Bear/player7.png");
		Image only8 = loadImage("images/Bear/player8.png");
		Image only9 = loadImage("images/Bear/player9.png");
		Image only10 = loadImage("images/Bear/player10.png");
		Image only11 = loadImage("images/Bear/player11.png");
		
		only.addFrame(only0, 175);
		only.addFrame(only1, 175);
		only.addFrame(only2, 175);
		only.addFrame(only3, 175);
		only.addFrame(only4, 175);
		only.addFrame(only5, 175);
		only.addFrame(only6, 175);
		only.addFrame(only7, 175);
		only.addFrame(only8, 175);
		only.addFrame(only9, 175);
		only.addFrame(only10, 175);
		only.addFrame(only11, 175);
		
		super.addAnimation(only);
		
		super.setAnimation("only");
		
	}
	
	@Override
	public void updateAnimation(Long elapsedTime) {
		super.updateAnimation(elapsedTime);
	}
	
	private Image loadImage(String fileName) {
        return Toolkit.getDefaultToolkit().getImage(fileName);
    }


	
	/*
	 * These functions are necessary because of the way it's written. Which is kind of poorly.
	 */
	@Override
	public double getXVelocity() {
		return vx;
	}

	@Override
	public double getZVelocity() {
		return vz;
	}


	
	
}